package ruru.client.ui.widgets;

import java.util.ArrayList;
import java.util.List;

import ruru.client.RuruDkp;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;

public class RaidListWidget extends Composite {
	private List raidWidgets;
	private VerticalPanel vp;
	private static int SIZE; 
	
	public RaidListWidget(List titles) {
		vp = new VerticalPanel();
		vp.addStyleName("raid-list-widget");
		initWidget(vp);
		
		loadRaidData(titles);

		System.out.println("loading raidListWidget done: " + (System.currentTimeMillis() - RuruDkp.start) + "ms");
	}
	
	/**
	 * Initializes this RaidWidgetList with a List of raids
	 * @param raidWidgets
	 */	
	public void loadRaidData(List raidTitles) {
		raidWidgets = new ArrayList();
		
		
		
		SIZE = 20;
		
		
		
		for(int i = raidTitles.size() - 1; i >= raidTitles.size() - 1 - SIZE; i--) {
			String title = (String) raidTitles.get(i);
			RaidWidget widget = new RaidWidget(title, i);
			raidWidgets.add(widget);
		}		
		
		
		displayRaids();
		RuruDkp.loading.setText("Loading... Done");
		RuruDkp.loading.setVisible(false);
	}
	
	private void displayRaids() {
		vp.clear();
		for(int i = 0; i < raidWidgets.size(); i++) {
			vp.add((RaidWidget) raidWidgets.get(i));
		}
		
		RaidWidget last = (RaidWidget) raidWidgets.get(raidWidgets.size() - 1);
		// last.addStyleName("raid-list-bottom");
	}
}